// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
#include <pollux/testing/gtest_utils.h>
#include <pollux/testing/functions/prestosql/function_base_test.h>

using namespace kumo::pollux::test;

namespace kumo::pollux::functions {
namespace {

class MapRemoveNullValuesTest : public test::FunctionBaseTest {};

TEST_F(MapRemoveNullValuesTest, general) {
  // bigint key
  auto data = make_row_vector({make_map_vector_from_json<int64_t, int32_t>({
      "{1:4, 2:5, 3:6}",
      "{-1:null, -2:5, -3:null}",
      "{}",
      "null",
  })});

  auto result = evaluate("map_remove_null_values(c0)", data);

  auto expected = make_map_vector_from_json<int64_t, int32_t>(
      {"{1:4, 2:5, 3:6}", "{-2:5}", "{}", "null"});

  assertEqualVectors(expected, result);

  // string key
  data = make_row_vector({make_map_vector_from_json<std::string, std::string>({
      "{\"ad\":null, \"bc\":null, \"cd\":null}",
  })});

  result = evaluate("map_remove_null_values(c0)", data);

  expected = make_map_vector_from_json<std::string, std::string>({"{}"});

  assertEqualVectors(expected, result);

  // empty input map
  data =
      make_row_vector({make_map_vector_from_json<std::string, std::string>({"{}"})});
  expected = make_map_vector_from_json<std::string, std::string>({"{}"});
  assertEqualVectors(expected, result);
}

} // namespace
} // namespace kumo::pollux::functions
